package me.edzh.spring.bootstrap.utils.http;

import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;

public class ClientHolder {
    private volatile static ClientHolder singleton;
    private OkHttpClient client;

    private static ClientHolder getSingleton() {
        if (singleton == null) {
            synchronized (ClientHolder.class) {
                if (singleton == null) {
                    singleton = new ClientHolder();
                }
            }
        }
        return singleton;
    }

    private ClientHolder() {
        client = new OkHttpClient.Builder().callTimeout(10, TimeUnit.SECONDS).build();
    }

    public static OkHttpClient getClient() {
        return getSingleton().client;
    }
}
